/*
微信登录
	返回 code
*/

export const wxlogin = () => {
	return new Promise((resolve, reject) => {
		uni.login({
			provider: 'weixin',
			success: function(loginRes) {
				resolve(loginRes);
			},
			fail(err) {
				reject(err)
			}
		})

	})
}

/*
获取微信用户信息 要先调用登录接口
	返回用户信息
*/
export const wxUserInfo = () => {
	return new Promise((resolve, reject) => {
		uni.getUserInfo({
			provider: 'weixin',
			success: function(res) {
				resolve(res);
			},
			fail(err) {
				reject(err)
			}
		});
	})
}

/*
	返回用户是否授权
*/
export const wxSessionKey = (loginCode) => {
	return new Promise((resolve, reject) => {
		let header = {
			'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
		}
		uni.request({
			method: 'POST',
			url: 'https://a.shiqin.wang/api/apiv2/GetWeiXinSessionKey',
			data: {
				code: loginCode
			},
			header: header
		}).then(res => {
			switch (res[1].data.code) {
				case 1:
					resolve(res[1].data.data)
					break
				case 0:
					resolve(res[1].data.data)
					break
				case 401:
					break
			}
		});
	})
}
